package com.jianying.shared;

public class Result {

	private int code;
	
	private String message;
	
	private Object entity;
	
	public static Result forEntity(Object entity) {
		return entity == null ? notFound() : ok(entity);
	}
	
	public static Result notFound() {
		return new Result(404, "not_found");
	}
	
	public static Result ok() {
		return new Result(200, "ok");
	}
	
	public static Result error() {
		return new Result(500, "error");
	}
	
	public static Result ok(Object entity) {
		return new Result(200, "ok", entity);
	}
	
	public static Result created(Object entity) {
		return new Result(201, "created", entity);
	}
	
	public Result(int code, String message) {
		this.code = code;
		this.message = message;
	}
	
	public Result(int code, String message, Object entity) {
		this.code = code;
		this.message = message;
		this.entity = entity;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getEntity() {
		return entity;
	}

	public void setEntity(Object entity) {
		this.entity = entity;
	}
}
